/**
 * 每个页（Pager）
 */

var BGLayer = require('./BGLayer');
var ImgLayer = require('./ImgLayer');
var PencilLayer = require('./PencilLayer');
require('node-easel');

	var Pager = function(canvasWidth,canvasHeight,pencilData) {
		//常用标识
		this.container = false;

		this.canvasWidth = canvasWidth;
		this.canvasHeight = canvasHeight;

		this.bgLayer = false;
		this.imgLayer = false;
		this.pencilLayer = false;
		
		//私有标识

		/**
		 * 初始化方法
		 * @param {String} canvasId 画板Id
		 * @param {Object} imgObj 图片对象属性有img,fileOrPpt
		 */
		this.init = function() {

			this.container = new createjs.Container();

			this.bgLayer = new BGLayer(new createjs.Container(),this.canvasWidth,this.canvasHeight);
			this.imgLayer = new ImgLayer(new createjs.Container());
			this.pencilLayer = new PencilLayer(new createjs.Container(),pencilData,this.canvasWidth,this.canvasHeight);

			this.container.addChildAt(this.bgLayer._layer,0);
			this.container.addChildAt(this.imgLayer._layer,1);
			this.container.addChildAt(this.pencilLayer._layer,2);

		}
		
		/**
		 * 在铅笔上画的方法
		 * @param {Object} obj 操作节点
		 * @param {Function} cb 操作回调
		 */
		this.pencilDraw = function(obj,cb){
			this.pencilLayer.draw(obj,cb);
		}
		
		/**
		 * 清空铅笔层
		 */
		this.clearPencil = function(){
			this.pencilLayer.clear();
		}
		
		/**
		 * 画图片
		 * @param {Object} obj 操作节点
		 */
		this.drawImg = function(obj){
			this.imgLayer.draw(obj);
		}
		
		/**
		 * 画背景
		 * @param {Object} obj 操作节点
		 */
		this.drawBg = function(obj){
			this.bgLayer.draw(obj);
		}

		/**
		 * 清空笔记
		 */
		this.clearPencil = function(){
			this.pencilLayer.clear();
		}

	};
module.exports = Pager;